package org.aom.entity.menu;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.aom.entity.base.IdEntity;
import org.aom.entity.security.User;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
 * 就像每个用户都拥有其角色一样，每个用户拥有其对应的Menu类型，不同的是一个用户暂时只拥有一种类型的目录内容
 * @author Saya
 *
 */

@Entity
@Table(name="ss_menu")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Menu extends IdEntity{
	
	private static final long serialVersionUID = 7579297857535009161L;

	private String menuName;

	private Set<User> users = new HashSet<User>();
	
	private List<ModuleItem> moduleItems = new ArrayList<ModuleItem>();
	
	public String getMenuName() {
		return menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	@OneToMany(fetch=FetchType.LAZY, cascade = { CascadeType.ALL }, mappedBy = "menu")
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@ManyToMany(targetEntity = ModuleItem.class, fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
	@JoinTable(joinColumns = { @JoinColumn(name = "menu_id") }, inverseJoinColumns = { @JoinColumn(name = "moduleitem_id") }, name = "ss_menu_moduleitem")
	public List<ModuleItem> getModuleItems() {
		return moduleItems;
	}

	public void setModuleItems(List<ModuleItem> moduleItems) {
		this.moduleItems = moduleItems;
	}
	
	
	
	
	
}
